

<template tag="以下文档内容为hycli自动生成">
  <el-dialog
    v-model="conf.visible"
    v-if="conf.visible" 
    :title="title"
    :width="conf.width"
    draggable
    align-center="true"
    :close-on-click-modal="false"
  >
<el-form :model="form"  ref="form" :rules="rules_aaarh">
    <el-row>
    <el-col :span="12">
    <!-- {"index":6,"raw":"logo","name":"logo","cname":"Logo","type":{"raw":"varchar(32)","name":"varchar","len":32,"dlen":0},"defValue":"","allowNull":false,"constraints":["l","le","v","c","u","rows(1)","tp(icon,l-le)"],"desc":{"raw":"LOGO","name":"LOGO"}} -->
    <!--LOGO 输入控件 -->
    <el-form-item prop="logo" label="LOGO" label-width="100px" label-position="right">
      <el-input clearable style="width: 100%" v-model="form.logo"  maxlength="32" 
      :rows="1"  placeholder="请输入LOGO"  />
      </el-form-item>
    </el-col>
    <el-col :span="12">
    <!-- {"index":7,"raw":"name","name":"name","cname":"Name","type":{"raw":"varchar(32)","name":"varchar","len":32,"dlen":0},"defValue":"","allowNull":false,"constraints":["q","l","le","v","c","u","DN","#like"],"desc":{"raw":"系统名称","name":"系统名称"}} -->
    <!--系统名称 输入控件 -->
    <el-form-item prop="name" label="系统名称" label-width="100px" label-position="right">
      <el-input clearable style="width: 100%" v-model="form.name"  maxlength="32" 
      :rows="0"  placeholder="请输入系统名称"  />
      </el-form-item>
    </el-col>
    <el-col :span="12">
    <!-- {"index":8,"raw":"ident","name":"ident","cname":"Ident","type":{"raw":"varchar(32)","name":"varchar","len":32,"dlen":0},"defValue":"","allowNull":false,"constraints":["l","le","v","c","u"],"desc":{"raw":"唯一标识","name":"唯一标识"}} -->
    <!--唯一标识 输入控件 -->
    <el-form-item prop="ident" label="唯一标识" label-width="100px" label-position="right">
      <el-input clearable style="width: 100%" v-model="form.ident"  maxlength="32" 
      :rows="0"  placeholder="请输入唯一标识"  />
      </el-form-item>
    </el-col>
    <el-col :span="12">
    <!-- {"index":9,"raw":"index_url","name":"index_url","cname":"IndexUrl","type":{"raw":"varchar(32)","name":"varchar","len":32,"dlen":0},"defValue":"","allowNull":true,"constraints":["l","le","v","c","u","rows(1)","tp(link,l-le-v)"],"desc":{"raw":"首页地址","name":"首页地址"}} -->
    <!--首页地址 输入控件 -->
    <el-form-item prop="index_url" label="首页地址" label-width="100px" label-position="right">
      <el-input clearable style="width: 100%" v-model="form.index_url"  maxlength="32" 
      :rows="1"  placeholder="请输入首页地址"  />
      </el-form-item>
    </el-col>
    <el-col :span="12">
    <!-- {"index":10,"raw":"login_url","name":"login_url","cname":"LoginUrl","type":{"raw":"varchar(32)","name":"varchar","len":32,"dlen":0},"defValue":"","allowNull":true,"constraints":["l","le","v","c","u","rows(1)"],"desc":{"raw":"登录地址","name":"登录地址"}} -->
    <!--登录地址 输入控件 -->
    <el-form-item prop="login_url" label="登录地址" label-width="100px" label-position="right">
      <el-input clearable style="width: 100%" v-model="form.login_url"  maxlength="32" 
      :rows="1"  placeholder="请输入登录地址"  />
      </el-form-item>
    </el-col>
    <el-col :span="12">
    <!-- {"index":11,"raw":"theme","name":"theme","cname":"Theme","type":{"raw":"varchar(32)","name":"varchar","len":32,"dlen":0},"defValue":"","allowNull":true,"constraints":["le","v","c","u","rows(1)"],"desc":{"raw":"主题样式","name":"主题样式"}} -->
    <!--主题样式 输入控件 -->
    <el-form-item prop="theme" label="主题样式" label-width="100px" label-position="right">
      <el-input clearable style="width: 100%" v-model="form.theme"  maxlength="32" 
      :rows="1"  placeholder="请输入主题样式"  />
      </el-form-item>
    </el-col>
    <el-col :span="12">
    <!-- {"index":12,"raw":"bg_url","name":"bg_url","cname":"BgUrl","type":{"raw":"varchar(32)","name":"varchar","len":32,"dlen":0},"defValue":"","allowNull":true,"constraints":["le","v","c","u","tp(file)"],"desc":{"raw":"背景图片","name":"背景图片"}} -->
    <!--背景图片 文件控件 -->
    <el-form-item prop="bg_url" label="背景图片" label-width="100px" label-position="right">
      <el-input clearable style="width: 100%" v-model="form.bg_url"  maxlength="32" 
        :rows="0" 
        placeholder="请输入背景图片地址或上传文件"  >
        <template #append>
          <el-upload multiple :show-file-list="false" :action="conf.uploadPath" :limit="100" :on-success="onUploadSuccess" >
            <el-button type="primary">选择文件</el-button>
          </el-upload>
        </template>
      </el-input>
    </el-form-item>
    </el-col>
    <el-col :span="12">
    <!-- {"index":13,"raw":"status","name":"status","cname":"Status","type":{"raw":"tinyint(1)","name":"tinyint","len":1,"dlen":0},"defValue":"1","allowNull":false,"constraints":["l","le","v","c","u","sl","tp(radio,c-u)","tp(switch,l)"],"desc":{"raw":"状态 0：启用 1: 禁用","name":"状态"}} -->
    <el-form-item prop="status" label="状态" label-width="100px" label-position="right">
      <el-radio-group v-model="form.status"   >
        <el-radio-button v-for="item in statusList" :key="item.value" :label="item.value" >
            {{item.name}}
        </el-radio-button>
      </el-radio-group>
      <el-tooltip raw-content="true" content="状态 0：启用 1: 禁用" placement="bottom" effect="light">
      <i class="form_item_info fa fa-info-circle"  aria-hidden="true" />
      </el-tooltip>
    </el-form-item>
    </el-col>
    </el-row>
</el-form>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="hide" icon="close">取消</el-button>
        <el-button type="primary" @click="save" icon="select">提交</el-button>
      </span>
    </template>
  </el-dialog>
</template>

<script>
import rtext from "@/views/cmpnts/rtext.vue"
export default {
  components: {
    rtext
},
  data() {
    return {
      conf: {
        visible: false,
        width:"60%",
        uploadPath:this.$theia.env.join("/file/upload"),
      },
      title:"修改系统信息",
rules_aaarh:{
    logo:[{required:true,message:"请输入LOGO",trigger: 'blur'}],
    name:[{required:true,message:"请输入系统名称",trigger: 'blur'}],
    ident:[{required:true,message:"请输入唯一标识",trigger: 'blur'}],
    index_url:[{required:false,message:"请输入首页地址",trigger: 'blur'}],
    login_url:[{required:false,message:"请输入登录地址",trigger: 'blur'}],
    theme:[{required:false,message:"请输入主题样式",trigger: 'blur'}],
    bg_url:[{required:false,message:"请输入背景图片",trigger: 'blur'}],
    status:[{required:true,message:"请输入状态",trigger: 'blur'}],
  },
    form:{
        logo:"",
        name:"",
        ident:"",
        index_url:"",
        login_url:"",
        theme:"",
        bg_url:"",
        status:"",
    },
    statusList:[],
    }
  },
  methods: {
    show(form) {
      this.conf.visible = true;
      this.loadEnums_aaarh()
      this.form = Object.assign(form,this.$route.params)
      this.get(form)
    },
      get(form){
        let that = this
        this.conf.loading = true
        let postForm = {}
        postForm.id = form.id
        this.$theia.http.get("/sso/system/info",postForm).then(res=>{
          that.form = Object.assign(that.form, res)
        //处理枚举重新绑定
          this.loadEnums_aaarh()
          that.conf.loading = false
        }).catch(res=>{
          let code = ((res||{}).response||{}).status||0
          let msg = `系统信息查询失败(${code})`
          that.$notify.error({title: '失败',message:msg ,duration:5000})
        })
    },
    save(){
        this.$refs.form.validate((v=>{
            if(v) this.onSave()
        }))
    },
    onSave(){
      let that = this
        let postForm = Object.assign({},this.form)
        this.$theia.http.put("/sso/system/info",postForm).then(res=>{
            that.$notify.success({title: '成功',message: '系统信息保存成功',duration:5000})
            that.$theia.enum.clear("system_info")
            that.$theia.enum.get("system_info")
            that.hide()
            that.$emit("onsaved")
        }).catch(res=>{
            let code = ((res||{}).response||{}).status||0
            let msg = `系统信息修改失败(${code})`
            that.$notify.error({title: '失败',message: msg,duration:5000})
        })
    },
    hide() {
      this.conf.visible = false;
      this.$refs.form.resetFields();
    },
     onUploadSuccess(response){
      this.form.bg_url = response.path
    },
    loadEnums_aaarh(){
        //状态
        this.statusList = this.$theia.enum.get("status","","" ,false,"")
    },

  },
};
</script>

<style scoped>
.form_item_info{
  margin-left: 4px;
  color:#999;
}
.form_item_info:hover{
  cursor: pointer;
  font-weight: 500;
  color:#333;
}
</style>